/*   Shotscreens
 *   Copyright (C) 2011, Andrew Lisin  (http://crystalnix.com)
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef FULLSCREENWIDGET_H
#define FULLSCREENWIDGET_H

#include <QWidget>
#include <QPixmap>
#include <QShortcut>
#include <QPoint>
#include <QRect>

QT_BEGIN_NAMESPACE
class QPaintEvent;
class QMouseEvent;
QT_END_NAMESPACE

namespace Ui
{
    class menuscreenshot;
}

class FullscreenWidget : public QWidget
{
    Q_OBJECT
public:
    explicit FullscreenWidget(const QPixmap& pixmap, QWidget *parent = 0);
    ~FullscreenWidget();

    typedef struct _WindowInfo {
        WId id;
        QString name;
        QRect frame;
        int layer;
    } WindowInfo;
private:
    enum { min_appropriate_size = 8 };

    QPixmap screenPixmap, originalPixmap, fillPixmap;
    QShortcut esc;
    QPoint firstPoint, secondPoint;

    bool holdLeftButton;
    bool allocating;
    bool selectingWindow;

    void prepare();
    void initializeShortcut();

    void drawPosRect(QMouseEvent*);
    void drawCursorLines(QMouseEvent*);
    void showMenu(QRect);

    QRect getRectFromPoints();

    Ui::menuscreenshot* ui;
    QWidget* menu;

    void connectButtons();



    QList<WindowInfo> windowsInfo;
    bool updateWindowsInfo();
    int  getWindowIndexAtPoint(const QPoint &pt);
    void hilightWindowAt(int index);
    QPixmap getQPixmapForWindowIndex(int index);

    QWidget hilighter;
    int currentWindowIndex;

    void switchToFrameSelectMode();

signals:
    void pixmapSended(QPixmap);

public slots:

private slots:
    void recaptureAction();
    void escAction();
    void videoAction();
    void imageAction();


protected:
    void paintEvent(QPaintEvent*);
    void mouseMoveEvent(QMouseEvent*);
    void mousePressEvent(QMouseEvent*);
    void mouseReleaseEvent(QMouseEvent*);
    void keyReleaseEvent(QKeyEvent *event);
};

#endif // FULLSCREENWIDGET_H
